package cn.lliiooll.launcher.update;

import cn.lliiooll.launcher.log.LogOut;

import javax.swing.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

public class Version {
	
	//private static String v;
  
	@SuppressWarnings({ })
	public static String getVersion() {
		try {
			File versionfile = new File("version.txt");
			FileInputStream version;
			byte[] b = new byte[1024];
			int i = 0;
			int index = 0;
			
			if(!(versionfile.exists())) {
				LogOut.error("版本文件不存在");
				JOptionPane.showMessageDialog(null,"没有找到版本文件,所以无法正常更新", "错误",JOptionPane.ERROR_MESSAGE); 
				System.exit(0);
				return "error";
			}else {
				String v1 = null;
				LogOut.info("读取版本文件");
				version = new FileInputStream(versionfile);
				try {
					while((i = version.read()) != -1) {
						b[index]=(byte) i;
						index++;
					}
					version.close();
					v1 = new String(b);
				} catch (Exception e) {
					
					e.printStackTrace();
				}
				LogOut.info("读取版本文件完成");
				if(v1.equals(null)) {
					JOptionPane.showMessageDialog(null,"没有找到版本文件,所以无法正常更新", "错误",JOptionPane.ERROR_MESSAGE); 
					System.exit(0);
					return "error";
				}else {
					LogOut.info("版本是" + v1);
					return v1;
				}
			}


		} catch (FileNotFoundException e) {
			e.printStackTrace();
			JOptionPane.showMessageDialog(null,"没有找到版本文件,所以无法正常更新", "错误",JOptionPane.ERROR_MESSAGE); 
			System.exit(0);
			return "error";
		}
	}
}